package com.appbee.core.client.place;

import com.google.gwt.place.shared.PlaceTokenizer;
import com.google.gwt.place.shared.Prefix;

public class StringIdPlace extends NamedPlace
{
	private String id;
	
	public StringIdPlace()
	{
		
	}
	
	public StringIdPlace(String name)
	{
		setName(name);
	}

	public StringIdPlace(String name,String id)
	{
		setName(name);
		this.id = id;
	}

	public String getId()
	{
		return id;
	}

	public void setId(String id)
	{
		this.id = id;
	}
	
	@Prefix("s")
	public static class Tokenizer implements PlaceTokenizer<StringIdPlace>
	{

		@Override
		public StringIdPlace getPlace(String token)
		{
			StringIdPlace p = new StringIdPlace();
			if(token!=null)
			{
				String[] split = token.split(":");
				p.setName(split[0]);
				if(split.length>1)
				{
					p.setId(split[1]);
				}
			}
			return p;
		}

		@Override
		public String getToken(StringIdPlace place)
		{
			StringBuffer sb = new StringBuffer();
			if(place!=null)
			{
				sb.append(place.getName());
				if(place.getId()!=null)
				{
					sb.append(":");
					sb.append(place.getId());
				}
			}
			return sb.toString();
		}
		
	}
	
}
